package iD220711010131;

import java.util.ArrayList;
import java.util.Scanner;

public class HuangJiaLe08 {
    
    static Scanner sc = new Scanner(System.in);
    static ArrayList<Goods> list = new ArrayList<Goods>();
    public static void main(String[] args) {
        Goods good01 = new Goods(1, "毛巾", "红色", 15, 46);
        list.add(good01);
        System.out.println("选择功能：");
        while(true) {
            System.out.println("1，商品添加");
            System.out.println("2，商品查看");
            System.out.println("3，商品删除");
            System.out.println("4，结束程序");
            int choice = sc.nextInt();
            if(choice == 1) {
                add();
                show();
            }else if(choice == 2) {
                show();
            }else if(choice == 3) {
                delete();
                show();
            }else if(choice == 4) {
                System.out.println("程序已关闭");
                break;
            }else {
                System.out.println("输入有误！！！");
            }
        }
        
    }
    private static void delete() {
        // TODO Auto-generated method stub
        System.out.println("是否删除商品，是——yes，否——no");
        String choice = sc.next();
        System.out.println("请选择需要删除的商品编号：");
        int id = sc.nextInt();
        if(choice.equals("yes")) {
            list.remove(id-1);
            System.out.println("商品" + id + "删除成功");
        }else if(choice.equals("no")) {
            return;
        }else {
            System.out.println("输入有误！！！");
        }
    }
    private static void show() {
        // TODO Auto-generated method stub
        for(Goods goods : list) {
            System.out.println(goods);
        }
    }
    private static void add() {
        // TODO Auto-generated method stub
        System.out.println("是否添加商品，是——yes，否——no");
        String choice = sc.next();
        //不能用choice == "yes"
        if(choice.equals("yes"))
            System.out.println("请输入商品编号");
            int id = sc.nextInt();
            System.out.println("请输入商品名称");
            String name = sc.next();
            System.out.println("请输入商品颜色");
            String color = sc.next();
            System.out.println("请输入商品价格");
            double price = sc.nextDouble();
            System.out.println("请输入商品数量");
            int count = sc.nextInt();
            Goods goods = new Goods(id, name, color, price, count);
            list.add(goods);
            System.out.println("商品" + id + "添加成功！！！");
    }

}class Goods {
    private int id;
    private String name;
    private String color;
    private double price;
    private int count;
    public Goods(int id, String name, String color, double price, int count) {
        super();
        this.id = id;
        this.name = name;
        this.color = color;
        this.price = price;
        this.count = count;
    }
    @Override
    public String toString() {
        return "Goods [id=" + id + ", name=" + name + ", color=" + color + ", price=" + price + ", count=" + count
                + "]";
    }
}
